package com.gosophia.conference.action.confPrepare;

import java.io.InputStream;
import java.net.URLEncoder;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.conferenceManagement.common.dto.DocumentDTO;
import com.gosophia.conferenceManagement.common.entity.DocumentInfo;
import com.gosophia.conferenceManagement.common.service.ConferenceFileService;
import com.gosophia.conferenceManagement.common.ws.ConferenceQueryWebService;
import com.gosophia.conferenceManagement.confPreparation.ws.ConfPreparationWebService;
/**
 * 下载会议材料
 * @author wangxinbing
 * @since  2011-3-29
 *  Copyright (c) 2010 Gosophia corporation All Rights Reserved
 */
@Component("DownloadConfMetailsAction")
@Scope("prototype")
public class DownloadConfMetailsAction extends BaseSupportAction {
	
	private String fileName;
	private String filePath;
	
	private Long docId;
	
	@Autowired
	private ConferenceQueryWebService conferenceQueryWebService;
	@Autowired
	private ConferenceFileService conferenceFileService; 
	

	@Override
	public String _execute() throws Exception {
		return SUCCESS;
	}
	public InputStream getInputStream() throws Exception {
		
		DocumentDTO docDTO = conferenceQueryWebService.findDocumentByDocumentId(docId);
		//获取文档
		DocumentInfo docInfo =conferenceFileService.loadDocumentByPath(docDTO.getDocumentPath());
		fileName = docDTO.getDocumentName();
        fileName = new String(fileName.getBytes("gbk"), "ISO-8859-1"); 
//		filePath = docDTO.getDocumentPath();
//		InputStream fileIo = ServletActionContext.getServletContext().getResourceAsStream(filePath);
        InputStream fileIo = docInfo.getDocumentContent();
		return fileIo;
	}
	public String getFileName() {
		return fileName;
	}
	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
	public String getFilePath() {
		return filePath;
	}
	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}
	public Long getDocId() {
		return docId;
	}
	public void setDocId(Long docId) {
		this.docId = docId;
	}
}
